package org.example.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.entity.UserStatus;

import java.time.LocalDateTime;

/**
 * 用户实体类
 */
@Data
@NoArgsConstructor
@TableName("tb_user")
public class User {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    private String username;
    
    private String email;
    
    private String phone;
    
    private String avatar;
    
    @TableField("status")
    private UserStatus status = UserStatus.ACTIVE;
    
    private Integer gender;
    
    private String birthday;
    
    private String address;
    
    private String remark;
    
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;
    
    private String createBy;
    
    private String updateBy;
    
    @Version
    private Integer version;
    
    @TableLogic
    private Integer deleted;
    
    /**
     * 创建新用户的构造函数
     */
    public User(String username, String email) {
        this.username = username;
        this.email = email;
        this.status = UserStatus.ACTIVE;
        this.createTime = LocalDateTime.now();
        this.updateTime = LocalDateTime.now();
        this.createBy = "system";
        this.updateBy = "system";
        this.version = 1;
        this.deleted = 0;
    }
}